﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace QandA
{
    public partial class CategoriesForm : Form
    {
        public CategoriesForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// This list of categories displayed in the list box
        /// </summary>
        public QuestionBankCategories Categories
        {
            get
            {
                QuestionBankCategories c = new QuestionBankCategories();
                if (CategoriesList.Items.Count != 0)
                {
                    c.category = new QuestionBankCategory[CategoriesList.Items.Count];
                    int i = 0;
                    foreach (object x in CategoriesList.Items)
                    {
                        c.category[i] = (QuestionBankCategory)x;
                        i++;
                    }
                }
                else
                {
                    c.category = null;
                }
                return c;
            }
            set
            {
                CategoriesList.Items.Clear();
                foreach(QuestionBankCategory x in value.category)
                {
                    CategoriesList.Items.Add(x, false);
                }
            }
        }

        /// <summary>
        /// The categories with check marks in the list box
        /// </summary>
        public QuestionBankCategories CheckedCategories
        {
            get
            {
                QuestionBankCategories c = new QuestionBankCategories();

                if (CategoriesList.CheckedItems.Count != 0)
                {
                    c.category = new QuestionBankCategory[CategoriesList.CheckedItems.Count];
                    int i = 0;
                    foreach (object x in CategoriesList.CheckedItems)
                    {
                        c.category[i] = (QuestionBankCategory)x;
                        i++;
                    }
                }
                else
                {
                    c.category = null;
                }
                return c;
            }
            set
            {
                int i;
                for (i = 0; i < CategoriesList.Items.Count; i++)
                {
                    CategoriesList.SetItemChecked(i, false);
                }
                foreach (QuestionBankCategory x in value.category)
                {
                    i = CategoriesList.Items.IndexOf(x);
                    if (i != -1)
                    {
                        CategoriesList.SetItemChecked(i, true);
                    }
                }
            }
        }

        private void OnOKClick(object sender, EventArgs e)
        {
            
            this.Close();
        }
    }
}
